package com.yungu.swift.admin.route.operation;

import com.alibaba.dubbo.config.annotation.Reference;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.yungu.swift.admin.consts.AdminErrorEnum;
import com.yungu.swift.assets.driver.model.dto.DriverChangeCarDto;
import com.yungu.swift.assets.driver.model.dto.DriverCheckDto;
import com.yungu.swift.assets.driver.model.param.*;
import com.yungu.swift.assets.driver.service.DriverChangeCarService;
import com.yungu.swift.assets.driver.service.DriverCheckService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.model.PageVo;
import com.yungu.swift.base.model.admin.AdminBusinessParam;
import com.yungu.swift.base.model.annotation.ResponseImgOverride;
import com.yungu.swift.constants.CommonConstant;
import com.yungu.swift.utils.ParamUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import static com.yungu.swift.admin.config.NacosListener.SYS_CONFIG;

/**
 * @author : cuixiuyin
 * @date : 2019/7/1
 */
@Slf4j
@RestController
@RequestMapping("/admin/v1/operation/driver/change")
@Api(value = "【运营管理】", tags = "司机资质审核")
public class DriverChangeCarAdmin {

    @Reference
    private DriverChangeCarService driverChangeCarService;

    @ResponseImgOverride
    @RequestMapping(value = "/queryPage", method = RequestMethod.POST)
    @ApiOperation(value = "司机更换车辆审核分页查询", httpMethod = "POST")
    public ResponseData<PageVo<DriverChangeCarDto>> queryPage(@RequestBody AdminDriverChangePageParam changePageParam) {
        if (ParamUtil.isIllegal(changePageParam.getStatus(), changePageParam.getBusinessType())) {
            return ResponseData.buildErrorResponse(AdminErrorEnum.PARAM_ERROR.getCode(), AdminErrorEnum.PARAM_ERROR.getMsg());
        }
        return driverChangeCarService.queryPage(changePageParam);
    }

    @ResponseImgOverride
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @ApiOperation(value = "司机资质审核信息详情", httpMethod = "GET")
    public ResponseData<DriverChangeCarDto> detail(@RequestParam String uuid) {
        return driverChangeCarService.get(uuid);
    }


    @RequestMapping(value = "/pass", method = RequestMethod.POST)
    @ApiOperation(value = "司机资质审核通过", httpMethod = "POST")
    public ResponseData<Boolean> pass(@RequestBody AdminDriverChangeCarParam changeCarParam) {
        if (ParamUtil.isIllegal(changeCarParam.getBusinessType())) {
            return ResponseData.buildErrorResponse(AdminErrorEnum.PARAM_ERROR.getCode(), AdminErrorEnum.PARAM_ERROR.getMsg());
        }
        return driverChangeCarService.pass(changeCarParam);
    }

    @RequestMapping(value = "/reject", method = RequestMethod.POST)
    @ApiOperation(value = "司机资质审核驳回", httpMethod = "POST")
    public ResponseData<Boolean> reject(@RequestBody AdminDriverChangeCarParam changeCarParam) {
        if (ParamUtil.isIllegal(changeCarParam.getRemark())) {
            return ResponseData.buildErrorResponse(AdminErrorEnum.PARAM_ERROR.getCode(), AdminErrorEnum.PARAM_ERROR.getMsg());
        }
        return driverChangeCarService.reject(changeCarParam);
    }
}
